package org.zoomdev.zoom.dao.driver.mysql;

import org.zoomdev.zoom.dao.ConnectionDescriptor;

public final class MysqlConnDescription extends ConnectionDescriptor {

    public static final int DEFAULT_PORT = 3306;

    public static final String DEFAULT_TIMEZONE = "Asia/Shanghai";

    private String dbName;

    private String encoding;
    private String timezone;

    public MysqlConnDescription() {
        this("localhost",
                DEFAULT_PORT,
                "zoom",
                "root",
                "root",
                DEFAULT_TIMEZONE);
    }

    public MysqlConnDescription(String server, int port, String db, String user, String password, String timezone) {
        setPassword(password);
        setUser(user);
        setDriverClass("com.mysql.jdbc.Driver");
        setServer(server);
        setDbName(db);
        setPort(port);
        setTimezone(timezone);
    }

    public MysqlConnDescription(String server, int port, String db, String user, String password) {
        this(server, port, db, user, password, DEFAULT_TIMEZONE);
    }


    public MysqlConnDescription(String server, String db, String user, String password) {
        this(server, DEFAULT_PORT, db, user, password, DEFAULT_TIMEZONE);
    }

    @Override
    public String getJdbcUrl() {
        return "jdbc:mysql://" + getServer() + ":" + getPort() + "/" + getDbName() + "?useUnicode=true&characterEncoding=UTF-8&serverTimezone=" + getTimezone();
    }

    public String getDbName() {
        return dbName;
    }


    public void setDbName(String dbName) {
        this.dbName = dbName;
    }


    public String getTimezone() {
        return timezone;
    }

    public void setTimezone(String timezone) {
        this.timezone = timezone;
    }

    public String getEncoding() {
        return encoding;
    }

    public void setEncoding(String encoding) {
        this.encoding = encoding;
    }
}
